package org.bookie.init.tasks;

import java.util.Properties;

import javax.mail.Session;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.hivemind.Registry;
import org.bookie.init.InitTask;

public class JNDIEmailCheck implements InitTask {

	private static final String MAIL_SESSION = "mail/Session";

	public Properties check(Registry reg) throws Exception {
		Properties props = new Properties();
		props.put("Java-Mail JNDI Reference Name", MAIL_SESSION);
		return props;
	}

	public Properties execute(Registry reg) throws Exception {
		Properties props = new Properties();
		Context ctx = new InitialContext();
		ctx = (Context) ctx.lookup("java:comp/env");		
		Session session = (Session) ctx.lookup(MAIL_SESSION);
		props.put("Session lookup", "OK");
		props.putAll(session.getProperties());
		return props;
	}

	public String getTitle() {
		return "JNDI Java-Mail Rererence";
	}

}
